import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import '../model/cartmodellist.dart';
class HomeSwiper1 extends StatefulWidget {
  HomeSwiper1({Key key}) : super(key: key);

  @override
  _HomeSwiper1State createState() => _HomeSwiper1State();
}

class _HomeSwiper1State extends State<HomeSwiper1> {
  ScrollController _scrollController = new ScrollController();
  bool lYs=false;
  bool lY;
  @override 
  void initState(){
    if(m1==[]){
      add(1);
      print('我没有数据');
    }else{
      setState(() {
        lYs=true;
        lY=true;
      });
      print('我有数据');
    }
  }
  @override
  Widget build(BuildContext context) {
    return lYs?  Container(
            child: StaggeredGridView.countBuilder(
                shrinkWrap: true,
                controller: _scrollController,
                itemCount: 5,
                // primary: false,
                crossAxisCount: 4,
                mainAxisSpacing: 10.0,
                crossAxisSpacing: 4.0,
                itemBuilder: (context, index) {
                  return
                      // SizedBox(
                      //   height: 150,
                      //   child:
                      InkWell(
                    onTap: () {
                  // this.lY?Navigator.of(context).pushNamed('/goodscommodity',arguments: {"id":this.goods['message'][index]}):print('请稍后');
                    },
                    child: Card(
                      elevation: 7.0, //设置阴影
                      clipBehavior: Clip.antiAlias, //设置圆角
                      //  child: AspectRatio(
                      //  aspectRatio: 16 / 10,
                      child: Column(
                        //  mainAxisAlignment: MainAxisAlignment.spaceAround,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          //  Image.network(c[index]['img'],fit:BoxFit.cover)
                          // AspectRatio(aspectRatio: 16/16,child:Image.network(c[index]['img'],fit: BoxFit.cover,),),
                          Expanded(
                              flex: index % 3 != 0 ? 3 : 8,
                              //  height: double.infinity,
                              child: Container(
                                child: Image.network(
                                  m1[index]==null?"http://dbyxs.xyz:3005/uploads/53a821a7f3010bea7d4aa97ef6d134a2":m1[index]['url'].split(',')[0],
                               //c[index]['img'],
                                //this.goods['message'][index]['url'].split(',')[0]||this.ly?m2[index]['url'].split(',')[0]: c[index]['img'],
                             //   this.goods['message'][index]['url'].split(',')[0],
                                  fit: BoxFit.cover,
                                  width: double.infinity,
                                ),
                              )),

                          Container(
                            padding: EdgeInsets.all(5),
                            child: Text(
                              '${this.lY?m1[index]['goodsname']:''}',
                              style: TextStyle(color: Colors.black26),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                          Container(
                            margin: EdgeInsets.all(5),
                            child: Row(children: <Widget>[
                              Text(
                                '￥${this.lY?m1[index]['price']:''}元',
                                style:
                                    TextStyle(color: Colors.red, fontSize: 14),
                              ),
                              SizedBox(
                                width: 5,
                              ),
                              Text('10人付款',
                                  style: TextStyle(
                                      color: Colors.black38, fontSize: 12))
                            ]),
                          ),
                          Container(
                            padding: EdgeInsets.all(5),
                            child: index % 3 != 0 ? Text('特价优惠',style: TextStyle(color: Colors.redAccent),) : Container(),
                          )
                          //  Expanded(
                          //    flex: 1,
                          //    child: Text('价格100'),
                          //  ),
                          // Expanded(child:  Text('我是你的'),flex:1)
                        ],
                      ),
                      // ),
                    ),
                  );
                  // );
                },
                // staggeredTileBuilder: (index) => StaggeredTile.fit(2),
                staggeredTileBuilder: (index) =>
                    // StaggeredTile.count(2, index == 0 ? 2.5 : 3)
                    StaggeredTile.count(2, index == 2 ? 2.5 : 2.8)
                //     // staggeredTileBuilder: (index) => StaggeredTile.fit(2),
                )
            // child: ListView.builder(itemBuilder: _getlist,itemCount: c.length,),
          ):Text('加载中');
    }
  //}
}